package fr.vahren.sriksal.dao.impl;

import org.springframework.jdbc.core.support.JdbcDaoSupport;

import fr.vahren.sriksal.dao.IAuthDao;

public class AuthDao extends JdbcDaoSupport implements IAuthDao {

	private static final String REQ_SELECT_USER = "SELECT COUNT(id_user) FROM USER WHERE login=? AND password=?";

	/* (non-Javadoc)
	 * @see fr.vahren.sriksal.dao.impl.IAuthDao#checkPassword(java.lang.String, java.lang.String)
	 */
	@Override
	public boolean checkPassword(String login, String password) {
		int count = getJdbcTemplate().queryForInt(REQ_SELECT_USER, login,
				password);
		return count == 1;
	}

	/* (non-Javadoc)
	 * @see fr.vahren.sriksal.dao.impl.IAuthDao#createUser(java.lang.String, java.lang.String)
	 */
	@Override
	public void createUser(String login, String password) {
		getJdbcTemplate().update("INSERT INTO sriksal.USER (login,password) VALUES (?,?)", login,password);
	}

}
